package com.briup.web.controller;

import com.briup.bean.BrowsingHistory;
import com.briup.bean.Shop;
import com.briup.bean.User;
import com.briup.service.IBrowsingHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private IBrowsingHistoryService browsingHistoryService;
    @GetMapping(value = {"/","/index","toIndex"})
    public String toIndex(Model model,HttpSession session){
        User user = (User) session.getAttribute("user");
        if(user!=null){
            List<BrowsingHistory> browsingHistories = browsingHistoryService.getUserBrowsingHistory(user.getId());
            //System.out.println(browsingHistories);
            model.addAttribute("recommendShops",browsingHistories);
        }
        return "index";
    }
    @GetMapping("/error")
    public String toError(){
        return "error";
    }

    @GetMapping(value = "/exit")
    public String toExit(HttpSession session){
        //2.获取或创建session对象
        session.removeAttribute("user");
        return "redirect:/index";
    }
}
